package rm.metrology.shared;

import java.io.Serializable;

import javax.persistence.Id;
import javax.validation.constraints.NotNull;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Unindexed;

@Cached
public class UserEntity implements Serializable {

	
	private static final long serialVersionUID = 1L;

	@Id 
	private Long fId;
	
	@Unindexed 
	private Long fCreatedAt = System.currentTimeMillis();
	
	@Unindexed 
	@NotNull(message="[Staff] is REQUIRED")
	private String fStaff;
	
	@Unindexed
	@NotNull(message="[Location] is REQUIRED")
	private String fLocation;
	
	@Unindexed
	@NotNull(message="[IsActive] is REQUIRED")
	private Boolean fIsActive;
	

	protected UserEntity() {
	}
	
	public UserEntity(String staff, LocationEnum locationType, Boolean isActive) {
		fStaff = staff;
		fLocation = locationType.toString();
		fIsActive = isActive;
	}	
	
	public final Long getId() {
		return fId;
	}
	
	public final Long getCreatedTime() {
		return fCreatedAt;
	}

	public final String getStaff() {
		return fStaff;
	}

	public final LocationEnum getLocationType() {
		return LocationEnum.toEnum(fLocation);
	}

	public final Boolean isActive() {
		return fIsActive;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof UserEntity) {
			UserEntity user = (UserEntity) obj;
			return fStaff.equals(user.getStaff());
		} else if (obj instanceof String) {
			return fStaff.equals(obj);			
		} else {
			return false;
		}
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(getClass().getName())
			   .append(" { Staff: \"").append(fStaff)
			   .append("\", CreatedAt: ").append(fCreatedAt)
			   .append(", LocationType: \"").append(fLocation)
			   .append("\", IsActive: ").append(fIsActive)
			   .append(" }");
		return builder.toString();
	}

}
